using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using TrueCode.Core.Aspects;

namespace EMan.Common.EnterpriseStructure
{
  [DataContract]
  public class Changeset< T >
  {
    [DataMember]
    private readonly IEnumerable< T > _added;

    [DataMember]
    private readonly IEnumerable< T > _modified;

    [DataMember]
    private readonly IEnumerable< int > _deleted;

    public Changeset( [NotNull] IEnumerable< T > added, [NotNull] IEnumerable< T > modified, [NotNull] IEnumerable< int > deleted )
    {
      #region Validation
      if( added == null ) throw new ArgumentNullException( "added" );
      if( modified == null ) throw new ArgumentNullException( "modified" );
      if( deleted == null ) throw new ArgumentNullException( "deleted" );

      if( !added.Any() && !modified.Any() && !deleted.Any() ) throw new ArgumentException( "Changeset is empty" );
      #endregion

      _added = added;
      _modified = modified;
      _deleted = deleted;
    }

    public IEnumerable< T > Added
    {
      get { return _added; }
    }

    public IEnumerable< T > Modified
    {
      get { return _modified; }
    }

    public IEnumerable< int > Deleted
    {
      get { return _deleted; }
    }
  }
}